﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Nereus.Zeus.Mvc
{
    public class NereusUtil
    {
        private static Regex _regex = new Regex(@"(?<=[A-Z])(?=[A-Z][a-z])|(?<=[^A-Z])(?=[A-Z])|(?<=[A-Za-z])(?=[^A-Za-z])");

        public static string AnalysisHeaderAndBody(string name, string header, int indexof)
        {
            if (name.IndexOf(header) == indexof)
            {
                return name.Substring(indexof + header.Length);
            }
            return string.Empty;
        }

        public static string AnalysisHeaderAndBody(string name, string header)
        {
            var nameList = SplitByParscal(name);
            var body = string.Empty;
            if (nameList[0].Equals(header, StringComparison.OrdinalIgnoreCase))
            {
                nameList.RemoveAt(0);
                foreach (var item in nameList)
                {
                    body += item;
                }
            }
            return body;
        }

        public static List<string> SplitByParscal(string name)
        {
            var result = _regex.Match(name);
            var nameList = new List<string>();
            foreach (var item in result.Groups)
            {
                nameList.Add(item.ToString());
            }
            return nameList;
        }
    }
}
